﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ProtoType.DataStorage;
using System.Windows.Navigation;
using ProtoType.ProtoTypeService;
using ProtoType;

namespace ProtoType
{
    public partial class AddForm : PhoneApplicationPage
    {
        DataStructureStore dss = new DataStructureStore();
        ProtoTypeServiceClient client;
        AppSettings apps = new AppSettings();

        public AddForm()
        {
            InitializeComponent();
            client = new ProtoTypeServiceClient();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string selectedIndex = "";
            if (NavigationContext.QueryString.TryGetValue("selectedIndex", out selectedIndex))
            {
                int index = int.Parse(selectedIndex);
            }
        }
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (apps.IsolatedStorageSavingSetting)
            {
                dss.CreateForm(txtFormName.Text, txtFormDes.Text);
            }
            if (apps.WebServiceSavingSetting)
            {
                client.CreateFormAsync(txtFormName.Text, txtFormDes.Text);
                client.CreateFormCompleted += new EventHandler<CreateFormCompletedEventArgs>(client_CreateFormCompleted);
            }
            NavigationService.Navigate(new Uri("/FormsList.xaml", UriKind.Relative));
        }

        void client_CreateFormCompleted(object sender, CreateFormCompletedEventArgs e)
        {
            string s = e.Result.ToString();
        }
    }
}